home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Utilities / Siege Watch 2.0 / MenuStuff.p < prev    next >
Encoding:
Text File  |  1994-04-23  |  2.2 KB  |  100 lines  |  [TEXT/PJMM]

  1. unit MenuStuff;
  2. interface
  3.     procedure HandleMenuChoice (menuChoice: LONGINT);
  4.     procedure GetNewPreferences;
  5. implementation
  6.     uses
  7.         Strings, Globals;
  8.  
  9.     const
  10.  
  11.         ABOUT_ITEM = 1;
  12.         APPLE_MENU_ID = 400;
  13.         FILE_MENU_ID = APPLE_MENU_ID + 1;
  14.         EDIT_MENU_ID = APPLE_MENU_ID + 2;
  15.         CLOCK_MENU_ID = APPLE_MENU_ID + 3;
  16.  
  17.     procedure HandleAppleChoice (theItem: INTEGER);
  18.         var
  19.             accName: Str255;
  20.             accNumber, itemNumber, dummy: INTEGER;
  21.             appleMenu: MenuHandle;
  22.     begin
  23.  
  24.         case theItem of
  25.             ABOUT_ITEM: 
  26.                 dummy := Alert(400, nil);
  27.  
  28.             otherwise
  29.                 begin
  30.                     appleMenu := GetMHandle(APPLE_MENU_ID);
  31.                     GetItem(appleMenu, theItem, accName);
  32.                     accNumber := OpenDeskAcc(accName);
  33.                 end;
  34.         end;
  35.     end;
  36. { if we have a copy command, stick the current date into the clipboard }
  37.     procedure HandleCopyItem;
  38.         var
  39.             dateString, timeString, spaceString: Str255;
  40.             time: LONGINT;
  41.             length: integer;
  42.             cPtr: Ptr;
  43.             pString: StringPtr;
  44.             lErr: LONGINT;
  45.             dForm: DateForm;
  46.     begin
  47.         GetDateTime(time);
  48.         IUTimeString(time, FALSE, timeString);
  49.         dForm := DateForm(1);
  50.         IUDateString(time, dForm, dateString);
  51.         spaceString := ', ';
  52.         dateString := Concat(dateString, spaceString);
  53.         dateString := Concat(dateString, timeString);
  54.         length := Ord(dateString[0]);
  55.         pString := @dateString;
  56.         cPtr := P2CStr(pString);
  57.         lErr := ZeroScrap;
  58.         lErr := PutScrap(length, 'TEXT', cPtr);
  59.     end;
  60.  
  61.     procedure HandleMenuChoice (menuChoice: LONGINT);
  62.         var
  63.             theMenu, theItem: INTEGER;
  64.             aMenuHandle: MenuHandle;
  65.     begin
  66.         if menuChoice <> 0 then
  67.             begin
  68.                 theMenu := HiWord(menuChoice);
  69.                 theItem := LoWord(menuChoice);
  70.                 case theMenu of
  71.                     APPLE_MENU_ID: 
  72.                         HandleAppleChoice(theItem);
  73.                     FILE_MENU_ID: 
  74.                         begin
  75.                             if theItem = 1 then
  76.                                 gDone := TRUE;
  77.                         end;
  78.                     EDIT_MENU_ID: 
  79.                         begin
  80.                             if theItem = 4 then
  81.                                 begin
  82.                                     HandleCopyItem;
  83.                                 end;
  84.                         end;
  85.                     CLOCK_MENU_ID: 
  86.                         begin
  87.                             HiliteMenu(0);
  88.                             aMenuHandle := GetMHandle(CLOCK_MENU_ID);
  89.                             DisableItem(aMenuHandle, 0);
  90.                             DrawMenuBar;
  91.                             GetNewPreferences;
  92.                             if gSpeechAvailable then
  93.                                 EnableItem(aMenuHandle, 0);
  94.                             DrawMenuBar;
  95.                         end;
  96.                 end;
  97.                 HiliteMenu(0);
  98.             end;
  99.     end;
  100. end.